pid=`ps -ef | grep java | grep $1 | grep -v grep | awk '{print $2}'`
service_name=`ps -ef | grep $1 | grep -v grep | awk '{print $12}'`
if [ -n "$pid" ]; then
    echo "正在停止进程 (PID: $pid)..."
    kill $pid

    # 等待进程退出（最多5秒）
    for i in {1..5}; do
        if ! ps -p $pid > /dev/null 2>&1; then
            break
        fi
        sleep 1
    done

    # 检查是否仍然存在
    if ps -p $pid > /dev/null 2>&1; then
        echo "警告: 进程未正常退出，尝试强制终止..."
        kill -9 $pid
        sleep 1
    fi
fi
echo "begin start app $1"
echo "$service_name"

nohup java -Xms128m -Xmx512m -jar $1 &
